<template>
  <el-dialog
    v-model="showRejectModal"
    width="423px"
    append-to-body
    :close-on-click-modal="false"
    custom-class="dialog_center"
  >
    <p class="text-color-000000 text-base mb-4">驳回原因</p>
    <div class="reject_reason">
      <el-form ref="formRef" :model="form" :rules="rules">
        <el-form-item>
          <el-input
            type="textarea"
            :rows="4"
            v-model="form.remark"
            placeholder="请填写驳回原因"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div class="dialog_common_btn flex justify-center">
      <el-button type="primary" @click="handleReject">确认</el-button>
      <el-button @click="showRejectModal = false">取消</el-button>
    </div>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'

// interface Props {}
// const props = withDefaults(defineProps<Props>(), {})

const emit = defineEmits(['submit'])

const formRef = ref<FormInstance>()

const showRejectModal = ref(false)

const form = reactive({
  remark: '',
})

const rules = reactive<FormRules>({
  remark: [
    {
      required: true,
      message: '请填写驳回原因',
      trigger: 'blur',
    },
  ],
})

// 驳回审批
const handleReject = async () => {
  if (!formRef.value) return
  await formRef.value.validate(async (valid, fields) => {
    if (valid) {
      emit('submit', form.remark)
    }
  })
}

defineExpose({
  showRejectModal,
  form,
})
</script>

<style lang="scss" scoped>
:deep(.dialog_center) {
  .el-dialog__header {
    display: none;
  }
  .el-dialog__body {
    padding: 16px 17px 28px !important;
  }
  .reject_reason {
    padding: 0 13px;
    margin-bottom: 41px;
    .el-textarea__inner {
      resize: none;
      border-color: #a6a6a6;
      border-radius: 0;
    }
  }
}
</style>
